home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 49.2 KB | 1,712 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UMailer.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
-
- #if qPowerTalk
-
- #ifndef __UMAILER__
- #include "UMailer.h"
- #endif
-
- // MacApp
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILEBASEDDOCUMENT__
- #include "UFileBasedDocument.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMAILABLE__
- #include "UMailable.h"
- #endif
-
- #ifndef __UMAILERVIEW__
- #include "UMailerView.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- //========================================================================================
- // GLOBAL Functions
- //========================================================================================
-
- SMPDrawImageUPP gMacAppImageProc;
-
- //----------------------------------------------------------------------------------------
- // Prototypes for local functions
- //----------------------------------------------------------------------------------------
-
- pascal void MacAppImageProc(long refcon, Boolean inColor);
- OCEPackedRecipient* StringToAddress(const CStr255& addressStr);
-
- //----------------------------------------------------------------------------------------
- // MacAppImageProc
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- pascal void MacAppImageProc(long refcon,
- Boolean inColor)
- {
- TDocument* theDocument = (TDocument *)refcon;
- MMailable* mailDoc = MA_DYNAMIC_CAST(MMailable, theDocument);
- if (mailDoc)
- mailDoc->ImageDocumentForLetter(inColor);
- }
-
- //----------------------------------------------------------------------------------------
- // InitUMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- void InitUMailer()
- {
- if (!HasAOCEToolBox())
- {
- #if qDebug
- ProgramBreak("InitUMailer called but AOCE isn't present.");
- #endif
- return;
- }
- FailNIL(gMacAppImageProc = NewSMPDrawImageProc(&MacAppImageProc));
-
- InitUMailerView();
- }
-
- //========================================================================================
- // CLASS TLetter
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment AOCEMailerRes
- MA_DEFINE_CLASS_M1(TLetter, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TLetter::TLetter
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TLetter::TLetter():
- fMailDoc(NULL),
- fDocument(NULL),
- fLetterTabber(NULL),
- fLetterDescriptor(NULL),
- fHasMailer(FALSE),
- fHasBeenSent(FALSE),
- fLetterExists(FALSE),
- fReplyToAll(TRUE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TLetter::~TLetter()
- {
- fLetterDescriptor = DisposeIfHandle(fLetterDescriptor);
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::ILetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::ILetter(MMailable* mailDoc)
- {
- IObject();
-
- fMailDoc = mailDoc;
- fDocument = MA_DYNAMIC_CAST(TDocument, mailDoc);
- FailNonObject(fDocument);
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::AddMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::AddMailer()
- {
- CTempDesc mySpec;
- fDocument->MakeObjectSpecifier(mySpec, fDocument->GetSpecifierForm());
-
- TAppleEvent* theEvent = TAppleEvent::MakeCreateElementEvent(gServerAddress, kAEWaitReply,
- mySpec, cMailer, kAEBeginning, CAEDesc::fgNullDesc, CAEDesc::fgNullDesc);
-
- TClientCommand* theSendAECmd = new TClientCommand;
- theSendAECmd->IClientCommand(cAECreateElement, gDispatcher, FALSE, FALSE,
- gDispatcher, theEvent);
-
- gDispatcher->PostCommand(theSendAECmd);
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::AddNativeMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::AddNativeMailContent(Boolean& /*okToSend*/)
- {
- // Override to add your document content in its own format.
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::AddSnapshotMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::AddSnapshotMailContent(Boolean& /*okToSend*/)
- {
- // Default implementation takes a snapshot of the mailer window.
-
- FailOSErr(SMPImage((WindowPtr)GetMailerWindowRef(), gMacAppImageProc, (long)fDocument, TRUE));
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::AddStandardMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::AddStandardMailContent(Boolean& /*okToSend*/)
- {
- // Override to add your document content in standard mail format.
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::CountContainedMailers:
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
-
- long TLetter::CountContainedMailers()
- {
- long count = 0;
-
- if (HasAOCEToolBox())
- {
- WindowRef theWindowPtr = GetMailerWindowRef();
- SMPMailerState theMailerState;
- FailOSErr(SMPGetMailerState((WindowPtr)theWindowPtr, &theMailerState));
- count = theMailerState.mailerCount;
- }
-
- return count;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DeleteMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DeleteMailer()
- {
- if (HasMailer())
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAECoreSuite, kAEDelete, gServerAddress, kAEWaitReply);
-
- TMailer* theMailer = (TMailer *)GetIndContainedMailer(CountContainedMailers());
-
- CTempDesc theMailerDesc;
- theMailer->MakeObjectSpecifier(theMailerDesc, formAbsolutePosition);
-
- theEvent->WriteParameter(keyDirectObject, theMailerDesc);
-
- TClientCommand* theCommand = new TClientCommand;
- theCommand->IClientCommand(cAEDelete, fDocument, FALSE, FALSE, fDocument, theEvent);
- fDocument->PostCommand(theCommand);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoAECreateMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DoAECreateMailer(TAppleEvent* message,
- TAppleEvent* reply)
- {
- AuthIdentity localIdentity;
- OSErr identityError;
-
- identityError = gMailing->GetAOCEIdentity(localIdentity, FALSE); // no user interaction
- if (identityError == kOCELocalIdentityDoesNotExist)
- identityError = gMailing->GetAOCEIdentity(localIdentity, TRUE);
-
- if (!HasMailer() && (identityError == noErr || identityError == kOCELocalAuthenticationFail))
- {
- FailOSErr(SMPInitMailer(0));
-
- CPoint dimensions = TMailerView::GetDimensions(kExpanded);
- MakeRoomForMailer(dimensions.v, kDontRedraw);
-
- fHasMailer = TRUE;
-
- TWindow* theWindow = GetMailerWindow();
-
- TMailerView* theMailerView = new TMailerView;
- theMailerView->IMailerView(this, theWindow, kExpanded);
- theMailerView->OpenNewMailer(kExpanded, kCanContract);
-
- if (!fLetterTabber)
- {
- fLetterTabber = new TLetterTabber();
- fLetterTabber->ILetterTabber(TRUE, this);
- theWindow->AddBehavior(fLetterTabber);
- }
-
- dimensions.v += 100;
- theWindow->SetResizeLimits(dimensions, theWindow->fResizeLimits[botRight]);
- if (theWindow->Focus())
- theWindow->ForceRedraw();
-
- TMailer* theMailer = GetIndContainedMailer(CountContainedMailers());
- CTempDesc theMailerDesc;
- theMailer->MakeObjectSpecifier(theMailerDesc, formAbsolutePosition);
- reply->WriteParameter(keyAEResult, theMailerDesc);
-
- theMailer->SetPropertiesFromEvent(message);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoAECreateReply
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DoAECreateReply(TAppleEvent* message,
- TAppleEvent* /*reply*/)
- {
- if (!HasMailer())
- {
- CTempDesc originalDocSpec;
- MScriptableObject *originalScriptableDoc = NULL;
- TDocument *originalDoc = NULL;
-
- message->ReadParameter(keyAEData, typeObjectSpecifier, originalDocSpec);
- originalScriptableDoc = TOSADispatcher::fgDispatcher->ResolveObjectSpecifier(originalDocSpec);
- FailNonObject(originalDoc = MA_DYNAMIC_CAST(TDocument, originalScriptableDoc));
-
- WindowRef originalWindow = NULL;
- MMailable *originalMailableDoc = NULL;
-
- originalMailableDoc = MA_DYNAMIC_CAST(MMailable, originalDoc);
- if (originalMailableDoc)
- {
- TLetter* originalLetter = originalMailableDoc->fLetter;
- if (originalLetter)
- originalWindow = originalLetter->GetMailerWindowRef();
- }
-
- FailOSErr(SMPInitMailer(0));
-
- CPoint dimensions = TMailerView::GetDimensions(kExpanded);
-
- MakeRoomForMailer(dimensions.v, kDontRedraw);
- fHasMailer = TRUE;
-
- TWindow* theWindow = this->GetMailerWindow();
-
- TMailerView* theMailerView = new TMailerView;
- theMailerView->IMailerView(this, theWindow, kExpanded);
-
- theMailerView->OpenReplyMailer(originalWindow, fReplyToAll, kExpanded, kCanContract);
-
- if (!fLetterTabber)
- {
- fLetterTabber = new TLetterTabber();
- fLetterTabber->ILetterTabber(TRUE, this);
- theWindow->AddBehavior(fLetterTabber);
- }
-
- dimensions.v += 100;
- theWindow->SetResizeLimits(dimensions, theWindow->fResizeLimits[botRight]);
-
- fMailDoc->SetReplyContents(originalDoc);
-
- if (theWindow->Focus())
- theWindow->ForceRedraw();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoAESend
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DoAESend(TAppleEvent* message,
- TAppleEvent* /*reply*/)
- {
- if (HasAOCEToolBox())
- {
- SMPSendOptions sendOptions;
- sendOptions.signWhenSent = message->ReadBoolean(keyAESignWhenSent);
-
- DescType thePriority = message->ReadEnum(keyAEPriority);
-
- switch(thePriority)
- {
- case enumPriorityLow:
- sendOptions.priority = kIPMLowPriority;
- break;
-
- case enumPriorityHigh:
- sendOptions.priority = kIPMHighPriority;
- break;
-
- case enumPriorityNormal:
- default:
- sendOptions.priority = kIPMNormalPriority;
- break;
- };
-
- SMPSendFormatMask whichFormats = 0;
-
- CStr255 nativeName;
- if (message->HasParameter(keyAEIncludeMainEnclFmt))
- {
- whichFormats += kSMPNativeMask;
- message->ReadString(keyAEIncludeMainEnclFmt, nativeName);
- }
-
- if (message->ReadBoolean(keyAEIncludeSnapShotFmt))
- whichFormats += kSMPImageMask;
-
- if (message->ReadBoolean(keyAEIncludeAppleMailFmt))
- whichFormats += kSMPStandardInterchangeMask;
-
- SendDocument((Ptr)&sendOptions, whichFormats, nativeName);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoForward
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DoForward()
- {
- // Create a new document in reply to this one.
- AuthIdentity localIdentity;
-
- if (gMailing->GetAOCEIdentity(localIdentity, TRUE) == noErr)
- {
- TMailerView* itsMailerView = this->GetMailerView();
- if(!itsMailerView->fMailerExpanded)
- itsMailerView->ExpandMailer();
- FailOSErr(SMPMailerForward((WindowPtr)GetMailerWindowRef(), localIdentity));
-
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoMailMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TLetter::DoMailMenuCommand(CommandNumber aCommandNumber)
- {
- Boolean handled = TRUE;
-
- switch (aCommandNumber)
- {
- case cAddMailer:
- if (HasAOCEToolBox())
- {
- if (this->HasMailer())
- this->DeleteMailer();
- else
- this->AddMailer();
- }
- break;
-
- case cSend:
- if (HasAOCEToolBox() && this->ValidateForSend())
- this->DoSend();
- break;
-
- case cReply:
- if (HasAOCEToolBox())
- this->DoReply();
- break;
-
- case cForward:
- if (HasAOCEToolBox())
- this->DoForward();
- break;
-
- default:
- handled = FALSE;
- break;
- }
-
- return handled;
- } // TLetter::DoMailMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoReply
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DoReply()
- {
- // Create a new document in reply to this one.
-
- CTempDesc mySpec;
- fDocument->MakeObjectSpecifier(mySpec, fDocument->GetSpecifierForm());
-
- CTempDesc appSpec;
- gDispatcher->MakeObjectSpecifier(appSpec);
-
- TAppleEvent* theEvent = TAppleEvent::MakeCreateElementEvent(gServerAddress, kAEWaitReply,
- appSpec, cReplyDocument, kAEBeginning, mySpec, CAEDesc::fgNullDesc);
-
- TClientCommand* theSendAECmd = new TClientCommand;
- theSendAECmd->IClientCommand(cAECreateElement, gDispatcher, FALSE, FALSE,
- gDispatcher, theEvent);
-
- gDispatcher->PostCommand(theSendAECmd);
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoSend
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::DoSend()
- {
- // Tell this document to send itself
-
- CStr255 nativeName;
- SMPSendFormat shouldSend;
- SMPSendOptions sendOptions;
-
- if (DoSendOptions((Ptr)&shouldSend, (Ptr)&sendOptions, nativeName))
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAEMailSuite, kAESendLetter, gServerAddress, kAEWaitReply);
-
- CTempDesc mySpecifier;
- fDocument->MakeObjectSpecifier(mySpecifier, formName);
- theEvent->WriteParameter(keyDirectObject, mySpecifier);
-
- if (shouldSend.whichFormats & kSMPImageMask)
- theEvent->WriteBoolean(keyAEIncludeSnapShotFmt, TRUE);
-
- if (shouldSend.whichFormats & kSMPStandardInterchangeMask)
- theEvent->WriteBoolean(keyAEIncludeAppleMailFmt, TRUE);
-
- if (shouldSend.whichFormats & kSMPNativeMask)
- theEvent->WriteString(keyAEIncludeMainEnclFmt, nativeName);
-
- if (sendOptions.signWhenSent)
- theEvent->WriteBoolean(keyAESignWhenSent, TRUE);
-
- DescType thePriority;
-
- switch(sendOptions.priority)
- {
- case kIPMLowPriority:
- thePriority = enumPriorityLow;
- break;
-
- case kIPMHighPriority:
- thePriority = enumPriorityHigh;
- break;
-
- case kIPMNormalPriority:
- default:
- thePriority = enumPriorityNormal;
- break;
- };
-
- theEvent->WriteEnum(keyAEPriority, thePriority);
-
- // Now send it off
- TClientCommand* theSendAECmd = new TClientCommand;
- theSendAECmd->IClientCommand(cSend, gDispatcher, FALSE, FALSE, gDispatcher,
- theEvent);
- gDispatcher->PostCommand(theSendAECmd);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::ValidateForSend
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TLetter::ValidateForSend()
- {
- WindowRef theWindow = GetMailerWindowRef();
- SMPMailerState theMailerState;
- Boolean canSend = TRUE;
- AuthIdentity localIdentity;
-
- // Get the local identity with user interaction allowed. This may
- // force the user to unlock their key chain
- if (gMailing->GetAOCEIdentity(localIdentity, TRUE) == noErr)
- {
- FailOSErr(SMPGetMailerState((WindowPtr)theWindow, &theMailerState));
- unsigned short whichMailer = theMailerState.currentMailer;
-
- unsigned short theSize = 0;
- FailOSErr(SMPGetComponentSize((WindowPtr)theWindow, whichMailer, kSMPRegarding, &theSize));
-
- MAVolatileInit(Ptr, subjectBuffer, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- FailNIL(subjectBuffer = NewPermPtr(theSize));
- // convert the subject field to a pascal string
- FailOSErr(SMPGetComponentInfo((WindowPtr)theWindow, whichMailer, kSMPRegarding, subjectBuffer));
- CStr255 subjectString(OCERToPString((RString *)subjectBuffer));
- subjectBuffer = DisposeIfPtr(subjectBuffer);
-
- if (subjectString.IsEmpty())
- {
- StdAlert(phNoSubject);
- canSend = FALSE;
- }
- fi.Success();
- }
- else // Recover
- {
- DisposeIfPtr(subjectBuffer);
- fi.ReSignal();
- }
-
- if (canSend) // test the recipient list
- {
- unsigned short numberOfAddresses;
- unsigned short nextItem;
- Boolean isMoreInfo;
-
- FailOSErr(SMPGetListItemInfo((WindowPtr)theWindow, whichMailer ,kSMPTo ,NULL, 0 , 0, &numberOfAddresses,
- &nextItem, &isMoreInfo));
-
- if (numberOfAddresses < 1)
- {
- StdAlert(phNoRecipient);
- canSend = FALSE;
- }
- }
- }
- else
- canSend = FALSE;
-
- return canSend;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoSendOptions
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TLetter::DoSendOptions(Ptr shouldSend,
- Ptr sendOptions,
- CStr255& nativeFormatName)
- {
- CStr255 appName;
- CStr255 docName;
-
- gDispatcher->GetApplicationName(appName);
- fDocument->GetTitle(docName);
- StringPtr nativeFormats[1];
- nativeFormats[0] = (StringPtr) & appName;
- SMPSendFormatMask canSend = fMailDoc->GetSendFormats();
- SMPSendFormat currentFormat;
- currentFormat.whichFormats = canSend;
- currentFormat.whichNativeFormat = 0;
- OSErr sendErr = SMPSendOptionsDialog((WindowPtr)GetMailerWindowRef(), docName,
- nativeFormats, 1, canSend, ¤tFormat, NULL,
- (long)fDocument, (SMPSendFormat*)shouldSend,
- (SMPSendOptions*)sendOptions);
- Boolean sendIt = sendErr == noErr;
- if (sendIt)
- nativeFormatName = (CStr255 &)*nativeFormats[((SMPSendFormat*)shouldSend)->whichNativeFormat];
- return (sendIt);
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::DoSetupMailMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TLetter::DoSetupMailMenus()
- {
- if (HasAOCEToolBox())
- {
- Enable(cAddMailer, TRUE);
- Boolean gotAMailer = this->HasMailer();
- SetMenuState(cAddMailer, kAOCEStrings, kAddMailerCmdName, kRemoveMailerCmdName, gotAMailer);
- if (gotAMailer)
- {
- SMPMailerState theMailerState;
- FailOSErr(SMPGetMailerState((WindowPtr)GetMailerWindowRef(), &theMailerState));
- Enable(cForward, theMailerState.hasBeenReceived);
- Enable(cReply, theMailerState.hasBeenReceived);
- Enable(cSend, !theMailerState.hasBeenReceived);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::GetDefaultTag
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::GetDefaultTag(CStr31& tagString)
- {
- tagString.Empty();
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::GetIndContainedMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- TMailer* TLetter::GetIndContainedMailer(short index)
- {
- TMailer* mailer = NULL;
-
- if (HasAOCEToolBox() && (index > 0) && (index <= this->CountContainedMailers()))
- {
- mailer = new TMailer;
- mailer->IMailer(this, GetMailerWindowRef(), index);
- TOSADispatcher::fgDispatcher->AddTemporaryToken(mailer);
- }
-
- return mailer;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::GetMailerView
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- TMailerView* TLetter::GetMailerView()
- {
- TWindow *mailerWindow = this->GetMailerWindow();
- return ((TMailerView*)mailerWindow->FindSubView(kMailerViewID));
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::GetMailerWindow
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- TWindow* TLetter::GetMailerWindow()
- {
- TWindow* mailerWindow = NULL;
-
- if (fDocument)
- {
- TList* windowList = fDocument->fWindowList;
- if ((windowList != NULL) && (windowList->GetSize() > 0))
- mailerWindow = (TWindow *)windowList->At(1);
- }
-
- return mailerWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::GetMailerWindowRef
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- WindowRef TLetter::GetMailerWindowRef()
- {
- TWindow* mailerWindow = GetMailerWindow();
- return mailerWindow ? mailerWindow->fWMgrWindow : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::HasMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TLetter::HasMailer()
- {
- return fHasMailer;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::LetterContentChanged
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::LetterContentChanged()
- {
- if (HasMailer())
- {
- WindowRef aWindow = GetMailerWindowRef();
- FailOSErr(SMPContentChanged((WindowPtr)aWindow));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::MakeRoomForMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::MakeRoomForMailer(long amount, Boolean redraw)
- {
- // It's usually easier to override in the mailable document,
- // so we delegate the job to it.
- fMailDoc->MakeRoomForMailer(amount, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::OpenLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::OpenLetter()
- {
- if (HasAOCEToolBox())
- {
- FailNIL(fLetterDescriptor);
- LetterDescriptor theSpec = **(LetterDescriptor**)fLetterDescriptor;
- TWindow* mailerWindow = this->GetMailerWindow();
- WindowRef theWindow = this->GetMailerWindowRef();
- OSErr err = noErr;
-
- FailOSErr(SMPInitMailer(0));
-
- CPoint dimensions = TMailerView::GetDimensions(kContracted);
-
- this->MakeRoomForMailer(dimensions.v, kDontRedraw);
- fHasMailer = TRUE;
-
- TMailerView* theMailerView = new TMailerView;
- theMailerView->IMailerView(this, mailerWindow, kContracted);
- theMailerView->OpenOldMailer(theSpec, kContracted, kCanContract);
-
- if (!fLetterTabber)
- {
- fLetterTabber = new TLetterTabber();
- fLetterTabber->ILetterTabber(TRUE, this);
- mailerWindow->AddBehavior(fLetterTabber);
- }
-
- dimensions.v += 100;
- mailerWindow->SetResizeLimits(dimensions, mailerWindow->fResizeLimits[botRight]);
-
- if (mailerWindow->Focus())
- mailerWindow->ForceRedraw();
-
- if (!theSpec.onDisk)
- {
- RString name;
- err = SMPGetComponentInfo((WindowPtr)theWindow, 1, kSMPRegarding, &name);
- if (err == noErr)
- {
- CStr255 theTitle(OCERToPString(&name));
- fDocument->SetTitle(theTitle);
- }
- }
-
- Boolean readContent;
-
- readContent = fMailDoc->ReadNativeMailContent();
-
- if (!readContent)
- readContent = fMailDoc->ReadSnapshotMailContent();
-
- if (!readContent)
- fMailDoc->ReadStandardMailContent();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::ReadLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::ReadLetter(Boolean /*forPrinting*/)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::ReadSnapshotMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TLetter::ReadSnapshotMailContent()
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::ReadStandardMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TLetter::ReadStandardMailContent()
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::ReadNativeMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TLetter::ReadNativeMailContent()
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::SaveLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::SaveLetter(CommandNumber /*itsCommandNumber*/)
- {
- this->SubClassResponsibility();
- }
-
- //----------------------------------------------------------------------------------------
- // TLetter::SendDocument
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::SendDocument(Ptr theSendOptions,
- unsigned long whichFormats,
- CStr255& /*nativeFormatName*/)
- {
- WindowRef theWindow = GetMailerWindowRef();
- Boolean addContent;
- OSType letterCreator;
- OSType letterType;
-
- if (whichFormats & kSMPNativeMask != 0)
- {
- letterCreator = fMailDoc->fMailCreator;
- letterType = fMailDoc->fMailType;
- }
- else
- {
- letterCreator = 'lap2';
- letterType = kStandardLetterFileType;
- }
-
- FailOSErr(MAInteractWithUser());
- FailOSErr(SMPBeginSend((WindowPtr)theWindow,letterCreator,letterType,
- (SMPSendOptions *)theSendOptions, &addContent));
-
- Boolean okToSend = TRUE; // can't be volatile because it is passed by reference
-
- if (addContent)
- {
- FailInfo fi;
- Try(fi)
- {
- if (whichFormats & kSMPStandardInterchangeMask)
- fMailDoc->AddStandardMailContent(okToSend);
-
- if (okToSend && (whichFormats & kSMPImageMask))
- fMailDoc->AddSnapshotMailContent(okToSend);
-
- if (okToSend && (whichFormats & kSMPNativeMask))
- fMailDoc->AddNativeMailContent(okToSend);
-
- fi.Success();
- }
- else // Recover
- {
- okToSend = FALSE;
- // fall through to EndSend
- }
- }
- FailOSErr(SMPEndSend((WindowPtr)theWindow, okToSend));
- fHasBeenSent = TRUE;
- } // TLetter::SendDocument
-
- //----------------------------------------------------------------------------------------
- // TLetter::SetLetterDesc
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TLetter::SetLetterDesc(Handle theDesc)
- {
- fLetterExists = TRUE;
- fLetterDescriptor = DisposeIfHandle(fLetterDescriptor);
- fLetterDescriptor = theDesc;
- fHasBeenSent = TRUE;
- }
-
- //========================================================================================
- // CLASS TFileBasedLetter
- //========================================================================================
- #undef Inherited
- #define Inherited TLetter
-
- #pragma segment AOCEMailerRes
- MA_DEFINE_CLASS_M1(TFileBasedLetter, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter::TFileBasedLetter
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TFileBasedLetter::TFileBasedLetter()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TFileBasedLetter::~TFileBasedLetter()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter::IFileBasedLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TFileBasedLetter::IFileBasedLetter(MMailable* mailDoc)
- {
- ILetter(mailDoc);
-
- fFileBasedDocument = MA_DYNAMIC_CAST(TFileBasedDocument, mailDoc);
- FailNonObject(fFileBasedDocument);
- }
-
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter::AddNativeMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TFileBasedLetter::AddNativeMailContent(Boolean& /*okToSend*/) // override
- {
- // Save to a temporary file then add as a main enclosure
-
- TFile* itsFile = fFileBasedDocument->GetFile();
-
- FSSpec saveFileSpec;
- itsFile->GetFileSpec(saveFileSpec); // Save file spec since it may be clobbered
-
- {
- CStr63 tmpName;
- fFileBasedDocument->GetTempName(tmpName);
-
- short tmpVRefNum;
- long tmpDirID;
- FailOSErr(FindFolder(saveFileSpec.vRefNum, kTemporaryFolderType, kCreateFolder,
- &tmpVRefNum, &tmpDirID));
- FailOSErr(itsFile->SpecifyWithTrio(tmpVRefNum, tmpDirID, tmpName));
- }
-
- Boolean didExist = fFileBasedDocument->fFileExists;
- fFileBasedDocument->fFileExists = FALSE;
- fFileBasedDocument->SaveFile(cSaveCopy, FALSE, TRUE, TRUE);
-
- FailOSErr(SMPAddMainEnclosure((WindowPtr)GetMailerWindowRef(), &itsFile->fFileSpec));
-
- itsFile->DeleteFile();
- itsFile->Specify(saveFileSpec);
- fFileBasedDocument->fFileExists = didExist;
- }
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter::ReadLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TFileBasedLetter::ReadLetter(Boolean /*forPrinting*/) // override
- {
- LetterDescriptor theSpec;
- theSpec.onDisk = TRUE;
-
- fFileBasedDocument->GetFile()->GetFileSpec(theSpec.u.fileSpec);
- fFileBasedDocument->fFileExists = TRUE;
-
- Handle theDescHdl = NewPermHandle(sizeof(theSpec));
- **(LetterDescriptor**)theDescHdl = theSpec;
- SetLetterDesc(theDescHdl);
-
- {
- CStr63 fileName;
- fFileBasedDocument->GetFileName(fileName);
- fFileBasedDocument->SetTitle(fileName);
- }
- fFileBasedDocument->SetChangeCount(0);
- }
-
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter::ReadNativeMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TFileBasedLetter::ReadNativeMailContent() // override
- {
- Boolean continueRead = FALSE;
- FSSpec enclosureDir;
-
- OSErr err = SMPGetMainEnclosureFSSpec((WindowPtr)GetMailerWindowRef(), &enclosureDir);
- if (err == noErr)
- {
- MAVolatileInit(TFile*, itsFile, fFileBasedDocument->GetFile());
- FSSpec saveFileSpec;
- itsFile->GetFileSpec(saveFileSpec); // Save file spec since it may be clobbered
-
- FailInfo fi;
- Try(fi)
- {
- itsFile->Specify(enclosureDir);
-
- Boolean forPrinting = FALSE;
- fFileBasedDocument->ReadFile(forPrinting);
-
- itsFile->Specify(saveFileSpec);
- continueRead = TRUE;
- fi.Success();
- }
- else // Recover
- {
- itsFile->Specify(saveFileSpec);
- fi.ReSignal();
- }
- }
-
- return continueRead;
- }
-
- //----------------------------------------------------------------------------------------
- // TFileBasedLetter::SaveLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TFileBasedLetter::SaveLetter(CommandNumber itsCommandNumber) // override
- {
- MAVolatileInit(WindowRef, theWindow, GetMailerWindowRef());
- MAVolatileInit(TFile*, aFile, fFileBasedDocument->GetFile());
-
- FSSpec theFSSpec;
- aFile->GetFileSpec(theFSSpec);
- OSType theType = gMailing->fMainLetterFileType; // use the letter file type
- OSType theCreator = aFile->fCreator;
-
- SMPSaveType theSaveType = kSMPSave;
- if (itsCommandNumber == cSaveAs)
- theSaveType = kSMPSaveAs;
- else if (itsCommandNumber == cSaveCopy)
- theSaveType = kSMPSaveACopy;
-
- if (fFileBasedDocument->fCommitOnSave || (itsCommandNumber != cSaveCopy))
- fFileBasedDocument->CommitLastCommand();
-
- Boolean addContent = FALSE;
- Boolean okToSend = TRUE;
- FailOSErr(SMPBeginSave((WindowPtr)theWindow, &theFSSpec, theCreator, theType, theSaveType,
- &addContent));
- if (addContent)
- {
- FailInfo fi;
- Try(fi)
- {
- unsigned long sendFormats = fMailDoc->GetSendFormats();
-
- if (sendFormats & kSMPStandardInterchangeMask)
- fMailDoc->AddStandardMailContent(okToSend);
-
- if (okToSend && (sendFormats & kSMPImageMask))
- fMailDoc->AddSnapshotMailContent(okToSend);
-
- if (okToSend && (sendFormats & kSMPNativeMask))
- fMailDoc->AddNativeMailContent(okToSend);
-
- fi.Success();
- }
- else // Recover
- {
- okToSend = FALSE;
- // fall through to EndSend
- }
- }
- FailOSErr(SMPEndSave((WindowPtr)theWindow, okToSend));
-
- fFileBasedDocument->fFileExists = TRUE;
- CStr63 name;
- aFile->GetName((CStr63 &)name);
-
- if (fFileBasedDocument->FileChanged(TRUE) == errFTypeChanged)
- fFileBasedDocument->fFile->GetFileType(fFileBasedDocument->fFile->fFileType);
-
- fFileBasedDocument->FileHasBeenSaved(name);
- }// TFileBasedLetter::SaveLetter
-
- //========================================================================================
- // CLASS TMailer
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment AOCEMailerRes
- MA_DEFINE_CLASS_M2(TMailer, Inherited, MScriptableObject);
-
- //----------------------------------------------------------------------------------------
- // TMailer::TMailer
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TMailer::TMailer()
- : MScriptableObject(cMailer),
- fWindow(NULL),
- fDocument(NULL),
- fLetter(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TMailer::~TMailer()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::IMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailer::IMailer(TLetter* letter,
- WindowRef theWindow,
- short whichMailer)
- {
- IObject();
-
- fWhichMailer = whichMailer;
- fWindow = theWindow;
- fLetter = letter;
- fDocument = letter->fDocument;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::TopMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TMailer::TopMailer()
- {
- WindowRef theWindowPtr = fWindow;
- SMPMailerState theMailerState;
- FailOSErr(SMPGetMailerState((WindowPtr)theWindowPtr, &theMailerState));
- return theMailerState.mailerCount == fWhichMailer;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::GetObjectsContainer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- MScriptableObject* TMailer::GetObjectsContainer()
- {
- return fDocument;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::GetObjectProperty
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TMailer::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- Boolean hasProperty = TRUE;
- FailInfo fi;
- Try(fi)
- {
- // Return properties for the mailer.
- WindowRef theWindowPtr = fWindow;
- SMPMailerState theMailerState;
- FailOSErr(SMPGetMailerState((WindowPtr)theWindowPtr, &theMailerState));
- switch (whichProperty)
- {
- case pContents:
- {
- thePropertyValue.CreateRecord();
- CTempDesc theSubjectDesc;
- this->GetObjectProperty(theSubjectDesc, pSubject, desiredType);
- thePropertyValue.PutKeyDesc(pSubject, theSubjectDesc);
- thePropertyValue.PutKeyBoolean(pReceived, theMailerState.hasBeenReceived);
- }
- break;
-
- case pName:
- case pSubject:
- {
- unsigned short theSize = 0;
- FailOSErr(SMPGetComponentSize((WindowPtr)fWindow, fWhichMailer, kSMPRegarding, &theSize));
-
- MAVolatileInit(Ptr, buffer, NULL);
- FailInfo fi2;
- Try(fi2)
- {
- buffer = NewPtr(theSize);
- FailOSErr(SMPGetComponentInfo((WindowPtr)fWindow, fWhichMailer, kSMPRegarding, buffer));
- CStr255 theString(OCERToPString((RString *)buffer));
- buffer = DisposeIfPtr(buffer);
- thePropertyValue.PutString(theString);
- fi2.Success();
- }
- else // Recover
- {
- buffer = DisposeIfPtr(buffer);
- fi.ReSignal();
- }
- }
- break;
-
- case pReceived:
- {
- thePropertyValue.PutBoolean(theMailerState.hasBeenReceived);
- }
- break;
-
- case pIndex:
- {
- thePropertyValue.PutLong(fWhichMailer);
- }
- break;
-
- default:
- hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
- }
- fi.Success();
- }
- else // Recover
- {
- hasProperty = FALSE;
- }
- return hasProperty;
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::SetObjectProperty
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailer::SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- // Set properties for the mailer.
- Boolean isTopMailer = this->TopMailer();
- switch (whichProperty)
- {
-
- case pContents:
- {
- CStr255 subjectStr;
- if (isTopMailer && thePropertyValue.GetKeyString(pSubject, subjectStr))
- {
- RString theSubRString;
- OCEPToRString(subjectStr, smRoman, &theSubRString, kRStringMaxBytes);
- SMPSetSubject((WindowPtr)fWindow, &theSubRString);
- }
- }
- break;
-
- case pName:
- case pSubject:
- if (isTopMailer)
- {
- CStr255 subjectStr;
- RString theSubRString;
- thePropertyValue.GetString(subjectStr);
- OCEPToRString(subjectStr, smRoman, &theSubRString, kRStringMaxBytes);
- SMPSetSubject((WindowPtr)fWindow, &theSubRString);
- }
- break;
-
- case pReceived:
- FailOSErr(errAECantSetReadOnly);
- break;
-
- default:
- MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::CountContainedObjects
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- long TMailer::CountContainedObjects(DescType desiredType)
- {
- if ((desiredType == cFile) || (desiredType == cRecipient))
- {
- SMPMailerComponent whichField = kSMPAttachments;
- if (desiredType == cRecipient)
- whichField = kSMPTo;
- unsigned short theSize = 0;
- FailOSErr(SMPGetComponentSize((WindowPtr)fWindow, fWhichMailer, whichField, &theSize));
- Ptr buffer = NewPtr(theSize);
- unsigned short startItem = 0;
- unsigned short itemCount = 0;
- unsigned short nextItem = 0;
- Boolean moreItems = FALSE;
- FailOSErr(SMPGetListItemInfo((WindowPtr)fWindow, fWhichMailer, whichField, buffer, theSize, startItem, &itemCount, &nextItem, &moreItems));
- DisposePtr(buffer);
- return itemCount;
- }
- else
- return MScriptableObject::CountContainedObjects(desiredType);
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::DoAEDelete
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TMailer::DoAEDelete(TAppleEvent* /* message */,
- TAppleEvent* /* reply */)
- {
- if (this->TopMailer())
- {
- TWindow * mailerWindow = fLetter->GetMailerWindow();
- SMPCloseOptions closeOptionsRec;
- BlockSet((Ptr) & closeOptionsRec, sizeof(SMPCloseOptions), 0);
- FailOSErr(SMPPrepareToClose((WindowPtr)fWindow)); //user may wish to extend this to
- //post dialog. See IM:AOCE App Interfaces
- //page 3-59
- FailOSErr(SMPDisposeMailer((WindowPtr)fWindow, &closeOptionsRec));
- fLetter->fHasMailer = FALSE;
-
- if (fLetter->fLetterTabber)
- {
- mailerWindow->RemoveBehavior(fLetter->fLetterTabber);
- fLetter->fLetterTabber = (TLetterTabber*)FreeIfObject(fLetter->fLetterTabber);
- }
-
- TView * theMailerView = fLetter->GetMailerView();
- mailerWindow->RemoveSubView(theMailerView);
- fLetter->MakeRoomForMailer(-theMailerView->fSize.v, kRedraw);
- FreeIfObject(theMailerView);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TMailer::GetIndContainedObject
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- MScriptableObject* TMailer::GetIndContainedObject(DescType desiredType,
- long index)
- {
- if ((desiredType == cRecipient) && (index > 0) && (index <= this->CountContainedObjects(cRecipient)))
- {
- TRecipient * theRecipient = new TRecipient;
- theRecipient->IRecipient(this, index, fWindow);
- return theRecipient;
- }
- else
- return MScriptableObject::GetIndContainedObject(desiredType, index);
- }
-
- //----------------------------------------------------------------------------------------
- // StringToAddress
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- OCEPackedRecipient* StringToAddress(const CStr255& addressStr)
- {
- CStr255 theStr = addressStr;
- DSSpec theDSSpec;
- BlockSet((Ptr) & theDSSpec, sizeof(theDSSpec), 0);
- RecordID rid;
- BlockSet((Ptr) & rid, sizeof(rid), 0);
- PackedRLI thePackedRLI;
- BlockSet((Ptr) & thePackedRLI, sizeof(thePackedRLI), 0);
- rid.rli = &thePackedRLI;
-
- short xSize = 0;
-
- short endOfMacName = theStr.Pos("@", 1);
- if (endOfMacName == 0)
- endOfMacName = theStr.Length() + 1;
- CStr32 machineName = theStr.Copy(1, endOfMacName - 1);
- CStr32 socketType = "MsgReceiver";
- CStr32 zoneName = "*";
- if (endOfMacName < theStr.Length())
- zoneName = theStr.Copy((endOfMacName + 1), theStr.Length() - endOfMacName);
- CStr255 typeName = "aoce Attribute Valuealanaoce mailslots";
-
- xSize = machineName.Length() + socketType.Length() + zoneName.Length() + 3;
- Ptr theExtension = NewPtrClear(xSize);
- Ptr xPtr = theExtension;
- long theLen = machineName.Length() + 1;
- MABlockMove((Ptr) & machineName, xPtr, theLen);
- xPtr += theLen;
- theLen = socketType.Length() + 1;
- MABlockMove((Ptr) & socketType, xPtr, theLen);
- xPtr += theLen;
- theLen = zoneName.Length() + 1;
- MABlockMove((Ptr) & zoneName, xPtr, theLen);
-
- RString theRecordName;
- RString theRecordType;
-
- theDSSpec.entitySpecifier = &rid;
- theDSSpec.extensionType = 'alan';
- theDSSpec.extensionSize = xSize;
- theDSSpec.extensionValue = theExtension;
-
- OCEPToRString(machineName, smRoman, &theRecordName, kRStringMaxBytes);
- rid.local.recordName = &theRecordName;
- OCEPToRString(typeName, smRoman, &theRecordType, kRStringMaxBytes);
- rid.local.recordType = &theRecordType;
-
- unsigned short theSpecSize = OCEPackedDSSpecSize(&theDSSpec);
- OCEPackedRecipient * theResult = (OCEPackedRecipient *)NewPtr(theSpecSize);
- FailOSErr(OCEPackDSSpec(&theDSSpec, (PackedDSSpec *)theResult, theSpecSize));
- DisposePtr(theExtension);
- return theResult;
- }// StringToAddress
-
- //========================================================================================
- // CLASS TRecipient
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment AOCERes
- MA_DEFINE_CLASS_M2(TRecipient, Inherited, MScriptableObject);
-
- //----------------------------------------------------------------------------------------
- // TRecipient::TRecipient
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TRecipient::TRecipient()
- : MScriptableObject(cRecipient),
- fWindow(NULL),
- fMailer(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRecipient destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRecipient::~TRecipient()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRecipient::IRecipient
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TRecipient::IRecipient(TMailer* theMailer,
- long index,
- WindowRef theWindow)
- {
- IObject();
- fWindow = theWindow;
- fMailer = theMailer;
- fWhichRecipient = index;
- }
-
- //----------------------------------------------------------------------------------------
- // TRecipient::GetObjectsContainer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- MScriptableObject* TRecipient::GetObjectsContainer()
- {
- return fMailer;
- }
-
- //----------------------------------------------------------------------------------------
- // TRecipient::GetObjectProperty
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean TRecipient::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- MAVolatileInit(Ptr, buffer, NULL);
- Boolean hasProperty = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- if (whichProperty == pName || whichProperty == pMailAddress || whichProperty == pRecipientType)
- {
- SMPMailerComponent whichField = kSMPTo;
- unsigned short theSize = kOCEPackedRecipientMaxBytes;
- FailNIL(buffer = NewPermPtr(theSize));
- unsigned short startItem = fWhichRecipient - 1;
- unsigned short itemCount = 0;
- unsigned short nextItem = 0;
- Boolean moreItems = FALSE;
- FailOSErr(SMPGetListItemInfo(fMailer->fWindow, fMailer->fWhichMailer, whichField, buffer,
- theSize, startItem, &itemCount, &nextItem, &moreItems));
-
- if (itemCount > 0)
- {
- switch (whichProperty)
- {
- case pRecipientType:
- {
- DescType theRecipientType;
- short recipientTypeID = *(short *)buffer;
-
- if (recipientTypeID == kSMPCCAddress)
- theRecipientType = kAECCRecipient;
- else if (recipientTypeID == kSMPBCCAddress)
- theRecipientType = kAEBCCRecipient;
- else if (recipientTypeID == kSMPToAddress)
- theRecipientType = kAEToRecipient;
- else
- FailOSErr(paramErr);
-
- thePropertyValue.PutEnum(theRecipientType);
- }
- break;
-
- case pName:
- {
- PackedDSSpecPtr theDSPtr = PackedDSSpecPtr(buffer + sizeof(short));
- CDSSpec aDSSpec(theDSPtr);
- thePropertyValue.PutString(aDSSpec.GetRecordName());
- }
- break;
-
- case pMailAddress:
- {
- PackedDSSpec* theDSPtr = (PackedDSSpec *)(buffer + sizeof(short));
- CTempDesc theDSSpecDesc;
- FailOSErr(AECreateDesc(typePackedDSSpec, buffer + sizeof(short), sizeof(ProtoPackedDSSpec) + theDSPtr->dataLength , theDSSpecDesc));
- DescType typeWanted = typeChar;
- if (desiredType.GetDataHandle())
- typeWanted = desiredType.GetType();
- FailOSErr(AECoerceDesc(theDSSpecDesc, typeWanted, thePropertyValue));
- }
- break;
-
- default:
- break; // will never get here
- }
- }
- else
- FailOSErr(errAENoSuchObject);
- }
- else
- hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- fi.Success();
- }
- else // recover
- {
- DisposeIfPtr(buffer);
- fi.ReSignal();
- }
-
- DisposeIfPtr(buffer);
- return hasProperty;
- }
-
- //----------------------------------------------------------------------------------------
- // TRecipient::SetObjectProperty
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TRecipient::SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- switch (whichProperty)
- {
- case pName:
- case pMailAddress:
- case pRecipientType:
- FailOSErr(errAECantSetReadOnly);
- break;
-
- default:
- MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
-
- #endif // qPowerTalk
-
- //----------------------------------------------------------------------------------------
- // End of UMailer.cp
-
- #pragma segment Inline
-